<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h3>已关联的应用</h3>
</div>
<div class="modal-body">
    <ul style="width:100%;height:120px;overflow-x:hidden;overflow-y:auto">
        {{#apps}}
        <li><a class="link" href="javascript:void(0)" link="{{ctx}}/system/cloud/unlink?appId={{id}}&cloudId={{cloudId}}">{{app_name}}</a></li>
        {{/apps}}
    </ul>
</div>
<div class="modal-footer">
    <button type="button" data-dismiss="modal" class="btn">关闭</button>
</div>
<script type="text/javascript">
    $("a.link").click(function(){
        var link = $(this);
        var $modal = $('#ajax-modal');
        $.ajax({
            url: link.attr("link"),
            dataType: "text",
            success: function(text) {
                $modal.modal('hide');
                bootbox.alert("<div><h4>取消关联成功</h4></div>", function() {
                    window.location.reload();
                });
            },
            error: function(xhr) {
                $modal.modal('hide');
                var html=[
                    "<div>",
                    "<h4>取消关联失败<br/>",xhr.responseText,"</h4>",
                    "</div"
                ].join('');
                bootbox.alert(html);
            }
        });
        return false;
    });
</script>
